package com.study.springboot.jpa.dao.impl;

import com.study.springboot.jpa.dao.TCityDao;
import com.study.springboot.jpa.entity.TCity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;

@Repository
public class TCityDaoImpl implements TCityDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public int insert(TCity user) {
        return 0;
    }

    @Override
    public int deleteById(Integer id) {
        return 0;
    }

    @Override
    public int update(TCity user) {
        return 0;
    }

    @Override
    public TCity getById(Integer id) {
                String sql = "select * from t_city where id = ?";
        return this.jdbcTemplate.queryForObject(sql, new RowMapper<TCity>() {

            @Override
            public TCity mapRow(ResultSet rs, int rowNum) throws SQLException {
                TCity city = new TCity();
                city.setId(rs.getInt("id"));
                city.setName(rs.getString("name"));
                return city;
            }

        },id);
    }
//    @Override
//    public User getById(Integer id) {
//        String sql = "select * from user where id = ?";
//        return this.jdbcTemplate.queryForObject(sql, new RowMapper<User>() {
//
//            @Override
//            public User mapRow(ResultSet rs, int rowNum) throws SQLException {
//                User user = new User();
//                user.setId(rs.getInt("id"));
//                user.setUsername(rs.getString("username"));
//                user.setPassword(rs.getString("password"));
//                user.setBirthday(rs.getDate("birthday"));
//                return user;
//            }
//
//        },id);
//    }
}
